﻿using BCCommon;
using BCDto.TMS.MoveHouseConfig.MoveHouseSpecificationServiceConfig;
using BCDto.TMS.MoveHouseConfig.MoveHouseSpecificationServiceConfig.MoveHouseSpecificationServiceConfigRequest;
using BCDto.TMS.MoveHouseConfig.MoveHouseSpecificationServiceConfigOverWrite;
using BCService.TMS.MoveHouseConfig.MoveHouseSpecificationServiceConfig;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace BCTMSRESTful.Controllers.Management.TMS.MoveHouseConfig
{
    /// <summary>
    /// 搬家规格服务设置
    /// </summary>
    [Route("api/v1/sim/[controller]")]
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    public class MoveHouseSpecificationServiceConfigController : ManagementBaseController
    {
        private readonly IMoveHouseSpecificationServiceConfigService moveHouseSpecificationServiceConfigService;
        private readonly IMoveHouseSpecificationServiceConfigOverWriteService moveHouseSpecificationServiceConfigOverWriteService;
        public MoveHouseSpecificationServiceConfigController(IMoveHouseSpecificationServiceConfigService moveHouseSpecificationServiceConfigService,
            IMoveHouseSpecificationServiceConfigOverWriteService moveHouseSpecificationServiceConfigOverWriteService)
        {
            this.moveHouseSpecificationServiceConfigService = moveHouseSpecificationServiceConfigService;
            this.moveHouseSpecificationServiceConfigOverWriteService = moveHouseSpecificationServiceConfigOverWriteService;
        }

        /// <summary>
        /// 获取总部价格(--全部)
        /// </summary>
        /// <param name="enabled">是否可用</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns>获取总部价格</returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<MoveHouseSpecificationServiceConfigViewDto>), 200)]
        public IActionResult GetAllPriceQuery(
            [FromQuery(Name = "enabled")] bool? enabled,
            [FromQuery(Name = "page_index")] int pageIndex,
            [FromQuery(Name = "page_size")] int pageSize)
        {
            var result = this.moveHouseSpecificationServiceConfigService.GetAllPriceQuery(this.Admin, enabled,
                pageIndex, pageSize);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取代理商价格(--代理商)
        /// </summary>
        /// <param name="countyCode">区编码</param>
        /// <param name="enabled">是否可用</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns>获取供应商搬家价格配置</returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<MoveHouseSpecificationServiceConfigOverWriteViewDto>), 200)]
        public IActionResult GetAllAgentPriceList(
            [FromQuery(Name = "county_code")] string countyCode,
            [FromQuery(Name = "enabled")] bool? enabled,
            [FromQuery(Name = "page_index")] int pageIndex,
            [FromQuery(Name = "page_size")] int pageSize)
        {
            var result = this.moveHouseSpecificationServiceConfigService.GetAllAgentPriceList(this.Admin,
                countyCode, enabled, pageIndex, pageSize);
            return this.Ok(result);
        }


        /// <summary>
        /// 开通服务(--代理商)
        /// </summary>
        /// <param name="countyCode">区编码</param>
        /// <param name="requestDto">规格服务Dto</param>
        /// <returns>开通服务</returns>
        [HttpPost]
        [Log("开通服务")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult Create(
            [FromQuery(Name = "county_code")] string countyCode,
            [FromBody] MoveHouseSpecificationServiceConfigIdRequestDto requestDto)
        {
            var result = this.moveHouseSpecificationServiceConfigService.Create(requestDto.MoveHouseSpecificationServiceConfigIds,
                countyCode, this.Admin);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取总部全部服务(--代理商)
        /// </summary>
        /// <returns>获取总部价格</returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<MoveHouseSpecificationServiceConfigViewDto>), 200)]
        public IActionResult GetAllServiceQuery()
        {
            var result = this.moveHouseSpecificationServiceConfigService.GetAllServiceQuery(this.Admin);
            return this.Ok(result);
        }


        #region 总部操作
        /// <summary>
        /// 删除规格服务(--总部)
        /// </summary>
        /// <param name="moveHouseSpecificationServiceConfigId">规格服务id</param>
        /// <returns>删除规格服务</returns>
        [HttpDelete("[action]/{move_house_specification_service_config_id}")]
        [Log("删除规格服务(--总部)")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "move_house_specification_service_config_id")] long moveHouseSpecificationServiceConfigId)
        {
            this.moveHouseSpecificationServiceConfigService.Delete(moveHouseSpecificationServiceConfigId, this.Admin);
            return NoContent();
        }

        /// <summary>
        /// 修改规格服务价格(--总部)
        /// </summary>
        /// <param name="moveHouseSpecificationServiceConfigId">规格服务id</param>
        /// <param name="price">价格</param>
        /// <returns>修改规格服务价格</returns>
        [HttpPut("[action]/{move_house_specification_service_config_id}/{price}")]
        [Log("修改规格服务价格(--总部)")]
        [ProducesResponseType(typeof(bool), 204)]
        public IActionResult Price([FromRoute(Name = "move_house_specification_service_config_id")] long moveHouseSpecificationServiceConfigId,
            [FromRoute(Name = "price")] decimal price)
        {
            var result = this.moveHouseSpecificationServiceConfigService.UpdatePrice(moveHouseSpecificationServiceConfigId, price, this.Admin);
            return this.Ok(result);
        }

        /// <summary>
        /// 修改规格服务是否可用(--总部)
        /// </summary>
        /// <param name="moveHouseSpecificationServiceConfigId">规格服务id</param>
        /// <param name="enabled">是否可用</param>
        /// <returns>删除规格服务</returns>
        [HttpPut("[action]/{move_house_specification_service_config_id}/{enabled}")]
        [Log("修改规格服务是否可用(--总部)")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Enabled([FromRoute(Name = "move_house_specification_service_config_id")] long moveHouseSpecificationServiceConfigId,
            [FromRoute(Name = "enabled")] bool enabled)
        {

            if (enabled)
                this.moveHouseSpecificationServiceConfigService.Enabled(moveHouseSpecificationServiceConfigId, this.Admin);
            else
                this.moveHouseSpecificationServiceConfigService.Disabled(moveHouseSpecificationServiceConfigId, this.Admin);
            return NoContent();
        }
        #endregion

        #region
        /// <summary>
        /// 删除规格服务(--代理商)
        /// </summary>
        /// <param name="moveHouseSpecificationServiceConfigOverWriteId">规格服务重写id</param>
        /// <returns>删除规格服务</returns>
        [HttpDelete("[action]/{move_house_specification_service_config_over_write_id}")]
        [Log("删除规格服务(--代理商)")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult AgentDelete([FromRoute(Name = "move_house_specification_service_config_over_write_id")] long moveHouseSpecificationServiceConfigOverWriteId)
        {
            this.moveHouseSpecificationServiceConfigOverWriteService.DeleteAsync(moveHouseSpecificationServiceConfigOverWriteId, this.Admin);
            return NoContent();
        }

        /// <summary>
        /// 修改规格服务价格(--代理商)
        /// </summary>
        /// <param name="moveHouseSpecificationServiceConfigOverWriteId">规格服务重写id</param>
        /// <param name="price"></param>
        /// <returns>修改规格服务价格</returns>
        [HttpPut("[action]/{move_house_specification_service_config_over_write_id}/{price}")]
        [Log("修改规格服务价格(--代理商)")]
        [ProducesResponseType(typeof(bool), 204)]
        public IActionResult AgentPrice([FromRoute(Name = "move_house_specification_service_config_over_write_id")] long moveHouseSpecificationServiceConfigOverWriteId,
            [FromRoute(Name = "price")] decimal price)
        {
            var result = this.moveHouseSpecificationServiceConfigOverWriteService.AgentPrice(moveHouseSpecificationServiceConfigOverWriteId, price, this.Admin);
            return this.Ok(result);
        }

        /// <summary>
        /// 修改规格服务是否可用(--代理商)
        /// </summary>
        /// <param name="moveHouseSpecificationServiceConfigOverWriteId">规格服务重写id</param>
        /// <param name="enabled">是否可用</param>
        /// <returns>修改规格服务是否可用</returns>
        [HttpPut("[action]/{move_house_specification_service_config_over_write_id}/{enabled}")]
        [Log("修改规格服务是否可用(--代理商)")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult AgentEnabled([FromRoute(Name = "move_house_specification_service_config_over_write_id")] long moveHouseSpecificationServiceConfigOverWriteId,
            [FromRoute(Name = "enabled")] bool enabled)
        {

            if (enabled)
                this.moveHouseSpecificationServiceConfigOverWriteService.Enabled(moveHouseSpecificationServiceConfigOverWriteId, this.Admin);
            else
                this.moveHouseSpecificationServiceConfigOverWriteService.Disabled(moveHouseSpecificationServiceConfigOverWriteId, this.Admin);
            return NoContent();
        }
        #endregion

    }
}
